using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_DanhSachMonHoc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
        {
            BoMonBUS bmBus = new BoMonBUS();
            lbBoMon.DataSource = bmBus.LayMang_BoMon();
            lbBoMon.DataValueField = "MaBoMon";
            lbBoMon.DataTextField = "TenBoMon";
            lbBoMon.DataBind();

            LoaiMonHocBUS lmhBus = new LoaiMonHocBUS();
            lbLoaiMon.DataSource = lmhBus.LayMang_LoaiMon();
            lbLoaiMon.DataValueField = "MaLoai";
            lbLoaiMon.DataTextField = "TenLoai";
            lbLoaiMon.DataBind();

            String maMonHoc = Request["idmh"];
            if (maMonHoc != null)
            {
                MonHocBUS monHocBus = new MonHocBUS();
                MonHocDTO monHocDto = new MonHocDTO();
                monHocDto = monHocBus.getMonHoc(maMonHoc);
                txtTenMonHoc.Text = monHocDto.TenMon;
                txtMaMonHoc.Text = monHocDto.MaMonHoc;
                txtSoTinChi.Text = monHocDto.SoTinChi.ToString();
            }
            else
            {
                btnCapNhat.Visible = false;
            }
        }
    }
    
    protected void btnHuy_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/DanhSachMonHoc.aspx");
    }
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        MonHocBUS monHocBus = new MonHocBUS();
        MonHocDTO monHocDto = new MonHocDTO();
        
        monHocDto.TenMon = txtTenMonHoc.Text  ;
        monHocDto.MaMonHoc = txtMaMonHoc.Text;
        monHocDto.SoTinChi = int.Parse(txtSoTinChi.Text);
        monHocDto.MaLoai = int.Parse(lbLoaiMon.SelectedItem.Value.ToString());
        monHocDto.MaBoMon = int.Parse(lbBoMon.SelectedItem.Value.ToString());
        monHocBus.update(monHocDto);
        Response.Redirect("~/Admin/DanhSachMonHoc.aspx");
    }
}
